home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / PBM.TRM < prev    next >
Text File  |  1992-03-25  |  7KB  |  285 lines

  1. /*
  2.  * $Id: pbm.trm,v 3.24 1992/02/29 16:23:41 woo Exp woo $
  3.  *
  4.  * $Log: pbm.trm,v $
  5.  * Revision 3.24  1992/02/29  16:23:41  woo
  6.  * gnuplot3.2, beta 4
  7.  *
  8.  * Revision 3.23  1992/02/21  20:18:16  woo
  9.  * gnuplot3.2, beta 3
  10.  *
  11.  */
  12.  
  13. /* GNUPLOT - pbm.trm */
  14. /*
  15.  * Copyright (C) 1990, 1991, 1992   
  16.  *
  17.  * Permission to use, copy, and distribute this software and its
  18.  * documentation for any purpose with or without fee is hereby granted, 
  19.  * provided that the above copyright notice appear in all copies and 
  20.  * that both that copyright notice and this permission notice appear 
  21.  * in supporting documentation.
  22.  *
  23.  * Permission to modify the software is granted, but not the right to
  24.  * distribute the modified code.  Modifications are to be distributed 
  25.  * as patches to released version.
  26.  *  
  27.  * This software  is provided "as is" without express or implied warranty.
  28.  * 
  29.  * This file is included by ../term.c.
  30.  *
  31.  * This terminal driver supports:
  32.  *  pbm, pgm, ppm
  33.  *
  34.  * AUTHORS
  35.  *  Russell Lang
  36.  *
  37.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  38.  * 
  39.  */
  40.  
  41. /* The following pbmplus drivers use the generic bit mapped graphics
  42.    routines from bitmap.c to build up a bit map in memory.  The driver
  43.    interchanges colomns and lines in order to access entire lines
  44.    easily and returns the lines to get bits in the right order :
  45.    (x,y) -> (y,XMAX-1-x). */
  46. /* This interchange is done by calling b_makebitmap() with reversed 
  47.    xmax and ymax, and then setting b_rastermode to TRUE.  b_setpixel()
  48.    will then perform the interchange before each pixel is plotted */
  49. /* See Jef Poskanzer's excellent PBMplus package for more details of
  50.    the Portable BitMap format and for programs to convert PBM files  
  51.    to other bitmap formats. */
  52.  
  53. #ifdef PBM
  54.  
  55. /* make XMAX and YMAX a multiple of 8 */
  56. #define PBM_XMAX (640)
  57. #define PBM_YMAX (480)
  58. #define PBM_VCHAR (FNT5X9_VCHAR)
  59. #define PBM_HCHAR (FNT5X9_VCHAR)
  60. #define PBM_VTIC FNT5X9_HBITS
  61. #define PBM_HTIC FNT5X9_HBITS
  62.  
  63. static int pbm_font=1;    /* small font */
  64. /* 7=black, 0=white */
  65. static int pgm_gray[]={7,1,6,5,4,3,2,1,7};  /* grays  */
  66. /* bit3=!intensify, bit2=!red, bit1=!green, bit0=!blue */
  67. static int ppm_color[]={15,8,3,5,6,4,2,1,11,13,14}; /* colors */
  68.  
  69. PBMoptions()
  70. {
  71.     if (!END_OF_COMMAND) {
  72.         if (almost_equals(c_token,"s$mall"))
  73.             pbm_font=1;
  74.         else if (almost_equals(c_token,"m$edium"))
  75.             pbm_font=2;
  76.         else if (almost_equals(c_token,"l$arge"))
  77.             pbm_font=3;
  78.         else
  79.             int_error("expecting: small, medium, large",c_token);
  80.         c_token++;
  81.     }
  82. }
  83.  
  84.  
  85. PBMinit()
  86. {
  87. #ifdef vms
  88.    reopen_binary();
  89. #endif /* vms */
  90. #ifdef PC
  91.    reopen_binary();
  92. #endif /* PC */
  93. }
  94.  
  95.  
  96. PBMreset()
  97. {
  98. #ifdef vms
  99.    fflush_binary();
  100. #endif /* vms */
  101. }
  102.  
  103.  
  104. PBMsetfont()
  105. {
  106.     switch(pbm_font) {
  107.         case 1:
  108.             b_charsize(FNT5X9);
  109.             term_tbl[term].v_char = FNT5X9_VCHAR;
  110.             term_tbl[term].h_char = FNT5X9_HCHAR;
  111.             term_tbl[term].v_tic = FNT5X9_HBITS;
  112.             term_tbl[term].h_tic = FNT5X9_HBITS;
  113.             break;
  114.         case 2:
  115.             b_charsize(FNT9X17);
  116.             term_tbl[term].v_char = FNT9X17_VCHAR;
  117.             term_tbl[term].h_char = FNT9X17_HCHAR;
  118.             term_tbl[term].v_tic = FNT9X17_HBITS;
  119.             term_tbl[term].h_tic = FNT9X17_HBITS;
  120.             break;
  121.         case 3:
  122.             b_charsize(FNT13X25);
  123.             term_tbl[term].v_char = FNT13X25_VCHAR;
  124.             term_tbl[term].h_char = FNT13X25_HCHAR;
  125.             term_tbl[term].v_tic = FNT13X25_HBITS;
  126.             term_tbl[term].h_tic = FNT13X25_HBITS;
  127.             break;
  128.     }
  129. }
  130.  
  131.  
  132. PBMgraphics()
  133. {
  134.     PBMsetfont();
  135.     /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  136.     setting b_rastermode to TRUE */
  137.     b_makebitmap((unsigned int)(PBM_YMAX*ysize),
  138.                      (unsigned int)(PBM_XMAX*xsize),1);
  139.     b_rastermode = TRUE;
  140. }
  141.  
  142.  
  143. PBMtext()
  144. {
  145.   register int x,j,row;
  146.  
  147.    fprintf(outfile,"P4\n");
  148.    fprintf(outfile,"%u %u\n", b_ysize, b_xsize);
  149.  
  150.    /* dump bitmap in raster mode */
  151.    for (x = b_xsize-1; x >= 0; x--) {
  152.       row = (b_ysize/8)-1;
  153.       for (j = row; j >= 0; j--) {
  154.          (void) fputc( (char)(*((*b_p)[j]+x)), outfile );
  155.       }
  156.    }
  157.  
  158.    b_freebitmap();
  159. }
  160.  
  161. #define PBMlinetype b_setlinetype
  162. #define PBMmove b_move
  163. #define PBMvector b_vector
  164. #define PBMtext_angle b_text_angle
  165. #define PBMtext_angle b_text_angle
  166. #define PBMput_text b_put_text
  167.  
  168. /* PGM functions */
  169. PGMgraphics()
  170. {
  171.     PBMsetfont();
  172.     /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  173.     setting b_rastermode to TRUE */
  174.     b_makebitmap((unsigned int)(PBM_YMAX*ysize),
  175.                      (unsigned int)(PBM_XMAX*xsize),3);
  176.     b_rastermode = TRUE;
  177.         b_setlinetype(0); /* solid lines */
  178. }
  179.  
  180.  
  181. PGMtext()
  182. {
  183.   register int x,j,row;
  184.   register int i,value;
  185.   int mask, plane1, plane2, plane3;
  186.  
  187.    fprintf(outfile,"P5\n");
  188.    fprintf(outfile,"%u %u\n", b_ysize, b_xsize);
  189.    fprintf(outfile,"%u\n",7);
  190.  
  191.    /* dump bitmap in raster mode */
  192.    for (x = b_xsize-1; x >= 0; x--) {
  193.       row = (b_ysize/8)-1;
  194.       for (j = row; j >= 0; j--) {
  195.          mask = 0x80;
  196.          plane1=(*((*b_p)[j]+x));
  197.          plane2=(*((*b_p)[j+b_psize]+x));
  198.          plane3=(*((*b_p)[j+b_psize+b_psize]+x));
  199.          for (i=0; i<8; i++) {
  200.             value=7;
  201.             if (plane1 & mask)  value-=1;
  202.             if (plane2 & mask)  value-=2;
  203.             if (plane3 & mask)  value-=4;
  204.             (void) fputc( (char)(value), outfile );
  205.             mask>>=1;
  206.          }
  207.       }
  208.    }
  209.  
  210.    b_freebitmap();
  211. }
  212.  
  213.  
  214. PGMlinetype(linetype)
  215. int linetype;
  216. {
  217.     if (linetype>=7)
  218.         linetype %= 7;
  219.     b_setvalue(pgm_gray[linetype+2]);
  220. }
  221.  
  222.  
  223. /* PPM functions */
  224. PPMgraphics()
  225. {
  226.     PBMsetfont();
  227.     /* rotate plot -90 degrees by reversing XMAX and YMAX and by 
  228.     setting b_rastermode to TRUE */
  229.     b_makebitmap((unsigned int)(PBM_YMAX*ysize),
  230.                      (unsigned int)(PBM_XMAX*xsize),4);
  231.     b_rastermode = TRUE;
  232.         b_setlinetype(0); /* solid lines */
  233. }
  234.  
  235.  
  236.  
  237. PPMtext()
  238. {
  239.   register int x,j,row;
  240.   register int i;
  241.   int mask, plane1, plane2, plane3, plane4;
  242.   int red, green, blue;
  243.  
  244.    fprintf(outfile,"P6\n");
  245.    fprintf(outfile,"%u %u\n", b_ysize, b_xsize);
  246.    fprintf(outfile,"%u\n",3);
  247.  
  248.    /* dump bitmap in raster mode */
  249.    for (x = b_xsize-1; x >= 0; x--) {
  250.       row = (b_ysize/8)-1;
  251.       for (j = row; j >= 0; j--) {
  252.          mask = 0x80;
  253.          plane1=(*((*b_p)[j]+x));
  254.          plane2=(*((*b_p)[j+b_psize]+x));
  255.          plane3=(*((*b_p)[j+b_psize+b_psize]+x));
  256.          plane4=(*((*b_p)[j+b_psize+b_psize+b_psize]+x));
  257.          for (i=0; i<8; i++) {
  258.             red = (plane3 & mask) ? 1 : 3;
  259.             green = (plane2 & mask) ? 1 : 3;
  260.             blue = (plane1 & mask) ? 1 : 3;
  261.             if (plane4 & mask) {
  262.                red--; green--; blue--;
  263.             }
  264.             (void) fputc( (char)(red), outfile );
  265.             (void) fputc( (char)(green), outfile );
  266.             (void) fputc( (char)(blue), outfile );
  267.             mask>>=1;
  268.          }
  269.       }
  270.    }
  271.  
  272.    b_freebitmap();
  273. }
  274.  
  275.  
  276. PPMlinetype(linetype)
  277. int linetype;
  278. {
  279.     if (linetype>=9)
  280.         linetype %= 9;
  281.     b_setvalue(ppm_color[linetype+2]);
  282. }
  283.  
  284. #endif /* PBM */
  285.